// pages/order/detail.js
import {
  getOrderDetail,
  confirmReceipt,
  customerServiceLog
} from "../../../api.js"
Page({
  data: {
    batchcode: ''
  },
  onLoad: function (options) {
    if (options.batchcode) {
      this.init(options.batchcode)
      this.setData({
        batchcode: options.batchcode
      })
    }
  },
  init(code) {
    let token = getApp().globalData.Store.token
    getOrderDetail(token, code).then(res => {
      if (res.data.code === 666) {
        this.setData({
          order: res.data.data
        })
      } else {
        wx.showToast({
          title: res.data.msg,
          icon: "none"
        })
      }
    })
  },
  //  基础信息复制
  handleInfoCopy(e) {
    let content = e.target.dataset.content
    wx.setClipboardData({
      data: content,
      success() {
        wx.showToast({
          title: '复制成功',
        })
      }
    })
  },
  // 确认收货 
  handleReceipt() {
    let token = getApp().globalData.Store.token
    let batchcode = this.data.order.order.batchcode
    confirmReceipt(token, batchcode).then(res => {
      if (res.data.code === 666) {
        wx.navigateTo({
          url: '/pages/order/afterreceipt',
        })
      } else {
        wx.showToast({
          title: res.data.msg,
          icon: "none"
        })
      }
    })
  },
  // 售后
  afterSale(e) {
    var index = e.currentTarget.dataset.ind
    wx.navigateTo({
      url: '/pages/money/afterSale/afterSale?name=' + this.data.order.order_info[index].full_name + '&pic=' + this.data.order.order_info[index].pic_url + '&money=' + this.data.order.order_info[index].pay_price + '&batchcode=' + this.data.order.order_info[index].info_batchcode,
    })
  },
  onShow() {
    getApp().startpage(new Date().getTime())
  },
  onHide() {
    getApp().endpage(new Date().getTime())
  },
  lianxi() {
    customerServiceLog(
      getApp().globalData.Store.token,
      2,
      '',
      this.data.batchcode
    ).then(res => {
      Console.log('cg')
    })
  }
})